package masterlink.sarPoint.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Util {
	private final static int diff=15;
	public static int compTimeNum(int time){
		int a=time ;
		int b=a / 100;
		int c=0;
//		System.out.println("a:"+a+", b:"+b);
		switch(b){
		case 8:
			c = a - 845;
			break;
		case 9:
			c = a - b*100 + diff;
			break;
		case 10:
			c = a - b*100 + diff + 60;
			break;
		case 11:
			c = a - b*100 + diff + 60 * 2;
			break;
		case 12:
			c = a - b*100 + diff + 60 * 3;
			break;
		case 13:
			c = a - b*100 + diff + 60 * 4;
			break;
		}
//		System.out.println("a:"+a+", b:"+b+", c:"+c);
		return c;
	}
	
	public static boolean isEmpty(String a){
		if(a==null || a.trim().length()==0){
			return true;
		}
		return false;
	}
	public static int getTickTime(int tick,int minute){
		tick = tick * minute;
		GregorianCalendar cal=new GregorianCalendar();
		cal.set(Calendar.HOUR_OF_DAY,8);
		cal.set(Calendar.MINUTE, 45);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		cal.add(Calendar.MINUTE, tick);
		int hour=cal.get(Calendar.HOUR_OF_DAY)*100;
		int min=cal.get(Calendar.MINUTE);
		return hour+min;
	}
	/**
	 * 取得今天日期
	 * @return 今天日期
	 */
	public static int getToday(){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		return Integer.parseInt(sdf.format(date));
	}
	/**
	 * 取得今年月份
	 * @return 今年月份
	 */
	public static String getMonth(){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
		return sdf.format(date);
	}
	/**
	 * 取得下個月的月份
	 * @return 今年下個月份
	 */
	public static String getNextMonth(){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
		Calendar calender = Calendar.getInstance();
		calender.setTime(date);
		calender.add(Calendar.MONTH, 1);
        return sdf.format(calender.getTime());
	}
}
